﻿using System;
using Landpy.CruiseControlNet.ConfigurationSidekick.ConfigTreeModule;

namespace Landpy.CruiseControlNet.ConfigurationSidekick.ConfigPropertyModule
{
    class ProjectSecurityHandler : GetPropertiesHandler
    {
        public override object GetPropertiesObject(GetPropertiesContext getPropertiesContext)
        {
            var treeNodeIndentity = this.GetTreeNodeIndentity(getPropertiesContext);
            if (treeNodeIndentity.Type == TreeNodeType.ProjectSecurity)
            {
                var queryProject = this.ProjectRepository.GetProjectById(getPropertiesContext.CruiseControl, new Guid(treeNodeIndentity.Key));
                if (queryProject != null)
                {
                    return queryProject.Security;
                }
            }
            return this.Successor.GetPropertiesObject(getPropertiesContext);
        }
    }
}
